<template>
  <div>
    <el-dialog
      :title="info.isAdd ? '添加管理员' : '编辑管理员'"
      center
      :visible.sync="info.isshow"
      :before-close="cancel"
    >
      <el-form :rules="rules" :model="memberForm" ref="member">
        <el-form-item prop="phone" label="手机号" :label-width="formLabelWidth">
          <el-input v-model="memberForm.phone" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item
          prop="nickname"
          label="昵称"
          :label-width="formLabelWidth"
        >
          <el-input v-model="memberForm.nickname" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item
          prop="password"
          show-password
          auto-complete="new-password"
          label="密码"
          :label-width="formLabelWidth"
        >
          <el-input v-model="memberForm.password" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item prop="status" label="状态" :label-width="formLabelWidth">
          <el-switch
            v-model="memberForm.status"
            active-color="#13ce66"
            inactive-color="#ff4949"
            :active-value="1"
            :inactive-value="2"
          >
          </el-switch>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="editMember">修改</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { mapActions, mapGetters } from "vuex";
import { memberInfo,memberEdit } from "../../util/request/api";
export default {
  props: ["info"],
  mounted() {
    this.getMemberList();
  },
  data() {
    return {
      formLabelWidth: "120px",
      memberForm: {
        uid: 0,
        nickname: "",
        password: "",
        phone: "",
        status: 1,
      },
      rules: {
        username: [
          { required: true, message: "请输入管理员名称", trigger: "blur" },
          { min: 2, max: 6, message: "长度在 2 到 6 个字符", trigger: "blur" },
        ],
        roleid: [
          { required: true, message: "请选择所属角色", trigger: "change" },
        ],
      },
    };
  },
  computed: {
    ...mapGetters({
      memberlist: "member/getMemberList",
    }),
  },

  methods: {
    ...mapActions({
      getMemberList: "member/getMemberAction",
    }),
    empty() {
      this.memberForm = {
        uid: 0,
        nickname: "",
        password: "",
        phone: "",
        status: 1,
      };
    },
    cancel() {
      this.$emit("cancel", false);
      this.empty();
    },
    lookup(uid) {
      memberInfo({ uid }).then((res) => {
        if (res.code == 200) {
          this.memberForm = res.list;
          this.memberForm.uid = uid;
        }
      });
    },
    editMember() {
      this.$refs.member.validate((valid) => {
        if (valid) {
          memberEdit(this.memberForm)
          .then((res) => {
            if (res.code == 200) {
              console.log('200成功'),
              this.getMemberList(),
              this.cancel();
            } else {
              this.$message.error(res.msg);
            }
          });
        }
      });
    },
  },
};
</script>

<style scoped>
</style>
